﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using NUnit.Framework;
using DomainDriver.CommonUtilities.Reflectors;

namespace DomainDriver.CommonUtilities.UnitTests.Reflectors
{
    [TestFixture]
    public class ClassReflectorTests
    {
        [Test]
        public void VerifyGetPropertiesWithAttributeDeclarationMethod()
        {
            int classPropertyCount = typeof(DummyTestObject).GetProperties().Length;
            Assert.AreEqual(3, classPropertyCount);

            IList<PropertyInfo> propertyInfos = ClassReflector.GetPropertiesWithAttributeDeclaration<TestAttribute>(typeof(DummyTestObject));
            Assert.AreEqual(2, propertyInfos.Count);

            propertyInfos = ClassReflector.GetPropertiesWithAttributeDeclaration<SecondTestAttribute>(typeof(DummyTestObject));
            Assert.AreEqual(1, propertyInfos.Count);
        }

        [Test]
        public void VerifyGetPropertiesForAttributeTypeMethod()
        {
            int classPropertyCount = typeof(DummyTestObject).GetProperties().Length;
            Assert.AreEqual(3, classPropertyCount);

            IDictionary<Type, IList<PropertyInfo>> propertyInfosByType = ClassReflector.GetPropertiesForAttributeType(typeof(DummyTestObject));
            Assert.AreEqual(2, propertyInfosByType.Count);
            Assert.AreEqual(2, propertyInfosByType[typeof(TestAttribute)].Count);
            Assert.AreEqual(1, propertyInfosByType[typeof(SecondTestAttribute)].Count);
        }

        [Test]
        public void VerifyGetNameForPropertyMethod()
        {
            string propertyName = ClassReflector.GetPropertyName((DummyTestObject testObject) => testObject.Property1);
            Assert.AreEqual("Property1", propertyName);
        }
    }
}